
#ifndef COMPILE_RUN
#include "header.hpp"
#endif

/*************************answer begin**************************/
class Answer
{
public:
    ListNode *reverseList(ListNode *head)
    {
        //三个指针反转
        if (head == NULL || head->next == NULL)
        {
            return head;
        }
        ListNode *n1 = NULL;
        ListNode *n2 = head;
        ListNode *n3 = head->next;
        while (n2)
        {
            n2->next = n1;
            n1 = n2;
            n2 = n3;
            if (n3)
                n3 = n3->next;
        }
        return n1;
    }
};
/*************************answer   end**************************/

ListNode *BuildList(const vector<int> &v)
{
    ListNode *next = nullptr;
    for (int i = v.size() - 1; i >= 0; --i)
    {
        ListNode *node = new ListNode(v[i], next);
        next = node;
    }
    return next;
}

void PrintList(ListNode *head)
{
    ListNode *cur = head;
    cout << "[";
    while (cur)
    {
        if (cur->next)
            cout << cur->val << ",";
        else
            cout << cur->val << "]" << endl;
        cur = cur->next;
    }
}

bool CompareList(ListNode *answer, ListNode *output)
{
    ListNode *cur1 = answer;
    ListNode *cur2 = output;
    while (cur1)
    {
        if (cur2 == nullptr || cur1->val != cur2->val)
            return false;
        cur1 = cur1->next;
        cur2 = cur2->next;
    }
    return true;
}

bool Test(const vector<int> &v)
{
    ListNode *list1 = BuildList(v);
    ListNode *list2 = BuildList(v);
    return CompareList(Answer().reverseList(list1), Solution().reverseList(list2));
}

int main()
{
    vector<vector<int>> v = {
        {3, 2, 5, 1, 6, 4, 2, 4, 3},
        {3},
        {1, 1, 1, 1, 1, 1},
        {-2, 3, 1, 5, 3, 2, 1, 5, 3},
        {5, 5, 5, 3, 3, 3},
        {6}};

    for (auto &e : v)
    {
        if (!Test(e))
        {
            cout << "测试用例: ";
            ListNode *list = BuildList(e);
            PrintList(list);
            cout << "你的输出: ";
            PrintList(Solution().reverseList(list));
            return 0;
        }
    }
    cout << "通过全部测试用例" << endl;
    return 0;
}